//
//  FeedbackViewController.m
//  CoachsBook
//
//  Created by huiyong li on 2022/8/31.
//

#import "FeedbackViewController.h"
#import "FeedbackCell.h"
#import "FeedbackModel.h"
#import "AddFeedbackViewController.h"
#import "FeedbackDetailsViewController.h"
@interface FeedbackViewController ()<UITableViewDelegate,UITableViewDataSource>

@end

@implementation FeedbackViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navgationheadv.titlelabel.text = @"反馈列表";
    
    self.navgationheadv.rightbtn.hidden = NO;
    self.navgationheadv.rightbtn.frame = CGRectMake(APPwidth-80, iPhoneXBool?SafeAreaTopHight/2+10:SafeAreaTopHight/2-5, 60, 20);
    [self.navgationheadv.rightbtn setTitle:@"新建" forState:0];
    [self.navgationheadv.rightbtn setTitleColor:rgba(22, 120, 255, 1) forState:0];
    [self.navgationheadv.rightbtn addTarget:self action:@selector(addBtnClick) forControlEvents:UIControlEventTouchUpInside];
    
    self.offset = 1;
}

- (void)setupUI {
    [super setupUI];

    self.refreshState = JKRefreshStateLoading;
    self.tableView.frame = CGRectMake(0, SafeAreaTopHight, APPwidth, APPheight-SafeAreaTopHight);
}


- (void)getData
{
    for (NSInteger i=0; i<(self.offset)*WKLLimit; i++) {
        FeedbackModel *model = [[FeedbackModel alloc]init];
        model.Feedbackstate = i%3;
        [self.dataArray addObject:model];
    }
    self.refreshState = JKRefreshStateFinish;
    [self.tableView reloadData];
}


#pragma mark - UITableViewDelegate,UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.dataArray.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 160;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    FeedbackCell *cell=[tableView dequeueReusableCellWithIdentifier:@"FeedbackCell"];
    if (!cell) {
        cell=[[FeedbackCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"FeedbackCell"];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    [cell cellFillWithModel:self.dataArray[indexPath.row]];
    return cell;
}


-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    FeedbackDetailsViewController *VC = [[FeedbackDetailsViewController alloc]init];
    [self.navigationController pushViewController:VC animated:YES];
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 15;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, APPwidth, 10)];
    view.backgroundColor = rgba(255, 255, 255, 1);
    return view;
}

-(void)addBtnClick
{
    
    AddFeedbackViewController *VC = [[AddFeedbackViewController alloc]init];
    [self.navigationController pushViewController:VC animated:YES];
}

@end
